#ifndef ASYNC_DEFS_H_
#define ASYNC_DEFS_H_

#include <pthread.h>
#include <sys/time.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <semaphore.h>
#include <string.h>

#include <string>

#include "atomic.h"
#include "memory.h"
#include "sync_utils.h"
#define _line(x) #x
#define line(x) _line(x)
enum LOG_LEVEL {TRACE = 0, DEBUG, NOTICE, WARNING, FATAL};
extern LOG_LEVEL g_loglevel;
#ifdef _LOG
	#define TRACE(logLevel,fmt, arg...) do{_trace(logLevel, __FILE__ " [" line(__LINE__) "]: " fmt "\n", ##arg);}while(0) 
	#define FATAL_LOG(fmt, arg...) TRACE(FATAL, fmt, ##arg)
	#define WARNING_LOG(fmt, arg...) TRACE(WARNING, fmt, ##arg)
	#define NOTICE_LOG(fmt, arg...) TRACE(NOTICE, fmt, ##arg)
	#define TRACE_LOG(fmt, arg...) TRACE(TRACE, fmt, ##arg)
	#define DEBUG_LOG(fmt, arg...) TRACE(DEBUG, fmt, ##arg)

	
#else
	#define TRACE(logLevel,fmt, ...)

	#define FATAL_LOG(fmt, arg...) 
	#define WARNING_LOG(fmt, arg...) 
	#define NOTICE_LOG(fmt, arg...) 
	#define TRACE_LOG(fmt, arg...) 
	#define DEBUG_LOG(fmt, arg...) 
#endif

#define FREE_POINTER(ptr) do{ delete ptr; ptr = NULL;}while(0)
#ifdef _DEBUG
	#include <assert.h>
	#define ASSERT_EQUAL(v1, v2) do{ assert(expression);}while(0)								
	#define ASSERT_NOT_NULL(expression) do { assert(expression != NULL);}while(0)
#else
	#define ASSERT_EQUAL(v1, v2) do { 																	\
										if (v1 != v2) {													\
											WARNING_LOG("assert (%d) == (%d) fail", v1, v2);			\
									}} while(0)
	#define ASSERT_NOT_NULL(e)   do {																	\
										if( e == NULL)													\
											WARNING_LOG("pointer is NULL");								\
									}while(0)
#endif
extern void _trace(LOG_LEVEL logLevel,const char* fmt, ...);
extern void set_log_file(FILE* fp);
#endif
